473,416 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Expand/Collapse DIVS

Hi,

I'm using the following javascript function to expand and collapse portions
of text in a web page (targeted at IE5.5 and above):

function doExpand(paraNum,arrowNum) {
if (paraNum.style.display=="none") {
paraNum.style.display="";
arrowNum.src="collapse.gif";
}
else {
paraNum.style.display="none";
arrowNum.src="expand.gif";
}
}

Implemented as follows:

<p><a href="javascript:doExpand(exp1,ar1)"><img src="expand.gif" id="ar1"
border="0" width="9" height="9"></a>
Title Text</p>
<div id="exp1" style="display: none" onclick="doExpand(exp1,ar1)">
<p>Drop down text here</p>
</div>

And repeated when required in the same page after changing the paraNum and
arrowNum parameters.

Does anyone know how I could adapt the script to enable more than one set of
DIVs to be expanded at the same time... i.e.: with a link that says "Show
All" and when clicked, all collapsed text on the page is then exapnded...?

Thanks in advance for any clues...

James Hurrell
--
..
Jul 20 '05 #1
1 22566
function doExpandAll( objImage ) {
var boolExpandAll = (objImage.src == 'expand.gif'); // Sets boolean
to true when expand image is clicked
for ( var intArg = 1; intArg < arguments.length; intArg++ ) { // Loop
through all the arguments (ignoring first one, which is the image)
var objDiv = arguments[intArg]; // Create a reference to each
div object in turn
objDiv.style.display = (boolExpandAll) ? 'block' : 'none'; // If
expanding set to visible, else set to hidden
}
objImage.src = (boolExpandAll) ? 'collapse.gif' : 'expand.gif'; // If
expanding set to collapse-image, else set to expand-image
}

<p><a href="javascript:doExpand(ar1,exp1,exp2,exp3)"><im g
src="expand.gif" id="ar1" border="0" width="9" height="9"></a> Title
Text</p>
<div id="exp1" style="display: none">
<p>Drop down text here</p>
</div>
<div id="exp2" style="display: none">
<p>Drop down text here</p>
</div>
<div id="exp3" style="display: none">
<p>Drop down text here</p>
</div>
Fred Basset
fr*********@whosyourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ireneatngs | last post by:
Hi, I have example html below which contains a couple of hidden divs. However, some of the table borders within these hidden divs are actually displayed when they should not be. In my...
1
by: Randy Starkey | last post by:
Hi, Is there a way to expand and collapse all if I have multiple implementations of this script on a single page? The script works well individually. Thanks! --Randy Starkey ---
4
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
1
by: Mel | last post by:
i am displaying the following (+ & - signs are images): + click on the sign to the left to expand after user clicks on the + sign - thanks for clicking item-1 item-2 item-3
0
by: Shadow Lynx | last post by:
When using ASP.NET 2.0's built-in TreeView on a page with <BASE target = "AnythingBut_Self"></BASE> in the HEAD, the expand/collapse buttons fail to function. The reason for this is that the...
2
by: sam | last post by:
Hi all, I have a series of divs in 2 blocks say BLOCK1 and BLOCK2 and I want to use one click to expand/collapse all those in each block. But the code I came up with exapands all the divs in the...
0
by: jim | last post by:
Hi, I have a TreeView control that sits on the MasterPage. All of my other webpages inherit from that Master Page. The Treeview receives it's data using an XMLDataSource that has it's DataFile...
4
by: Rabel | last post by:
I am not very good at javascript I mostly am a flash developer but I am trying to apply one of our old expanding menus to work for a new site but it doesn't collapse the way I need it to right now...
0
by: pbd22 | last post by:
Hi. I have two divs inside a containing div <div id=container> <div id=top> </div> <div id=bottom> </div> </div>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.